/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package freechoicepn.pflow;

import java.io.File;
import java.io.IOException;
import java.util.Scanner;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import org.w3c.dom.Document;
import org.w3c.dom.NodeList;

/**
 *
 * @author Tomas
 * 
 * Nacita pflow subor, vrati NodeListy pre miesta, prechody, sipky
 */
public class PflowLoader {
    
    private NodeList placeNodes;    // xml elementy <place>
    private NodeList transitionNodes; // xml elementy <transition>
    private NodeList arcNodes;  // xml elementy <arc>
    
    public PflowLoader(String filePath) {
        
        try {
            
            File xmlFile = new File(filePath);

            DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
            DocumentBuilder db = dbf.newDocumentBuilder();
            Document doc = db.parse(xmlFile);
            
            placeNodes = doc.getElementsByTagName("place");
            transitionNodes = doc.getElementsByTagName("transition");
            arcNodes = doc.getElementsByTagName("arc");
            
        } catch(IOException e) { 
            System.out.println("subor " + filePath + " sa nenasiel.");
            Scanner scanner = new Scanner(System.in);
            scanner.nextLine();
            System.exit(-1);
        } catch(Exception e) {  
            e.printStackTrace();
        }
    }

    public NodeList getPlaceNodes() {
        return placeNodes;
    }

    public NodeList getTransitionNodes() {
        return transitionNodes;
    }

    public NodeList getArcNodes() {
        return arcNodes;
    }
    
    
}
